

/*
* Copyright @ 2017 com.iflysse.trains
* crm 下午12:47:25
* All right reserved.
*
*/
	
package com.qf.dao.daoImpl;

import java.util.List;

import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.transaction.annotation.Transactional;

import com.qf.dao.CrmClassDao;
import com.qf.pojo.CrmClass;
import com.qf.pojo.CrmCourseType;
import com.qf.pojo.PageClass;
import com.qf.pojo.PageCourse;

/**
* @desc: crm
* @descripe:XXXX
* @author: 周锐
* @createTime: 2017年7月26日 下午12:47:25
* @history:
* @version: v1.0

*/
@Transactional(value="txManager")
public class CrmClassDaoImpl implements CrmClassDao {

	private HibernateTemplate htl;
	
	/*
	*(non-Javadoc)
	* @see com.qf.dao.CrmClassDao#addClass(com.qf.pojo.CrmClass)
	*/
		
	
	/**
	* @param htl the htl to set
	*/
	
	public void setHtl(HibernateTemplate htl) {
	
		this.htl = htl;
	}


	@Override
	public void addClass(CrmClass crmclass) {
		
		htl.save(crmclass);
			
	}

	
	/*
	*(non-Javadoc)
	* @see com.qf.dao.CrmClassDao#updateClass(com.qf.pojo.CrmClass)
	*/
		
	@Override
	public void updateClass(CrmClass crmclass) {
		
		htl.update(crmclass);
			
	}

	
	/*
	*(non-Javadoc)
	* @see com.qf.dao.CrmClassDao#findClassbyPage(int, int)
	*/
		
	@Override
	public List<CrmClass> findClassbyPage(int page, int size) {
		return htl.getSessionFactory().getCurrentSession().createQuery("from CrmClass",CrmClass.class).setFirstResult((page-1)*size).setMaxResults(size).getResultList();
		
	
			
	}


	
	/*
	*(non-Javadoc)
	* @see com.qf.dao.CrmClassDao#findClasspage()
	*/
		
	@Override
	public int findClasspage() {
		
		//TODO
		return htl.getSessionFactory().getCurrentSession().createQuery("from CrmClass",CrmClass.class).getResultList().size();
			
	}


	
	/*
	*(non-Javadoc)
	* @see com.qf.dao.CrmClassDao#findclassbyId(java.lang.Long)
	*/
		
	@Override
	public CrmClass findclassbyId(Long classId) {
		
		//TODO
		return htl.get(CrmClass.class, classId);
			
	}


	
	/*
	*(non-Javadoc)
	* @see com.qf.dao.CrmClassDao#findClassByCourseId(java.lang.Long)
	*/
		
	@Override
	public List<CrmClass> findClassByCourseId(Long courseTypeId) {
		
		//TODO
		CrmCourseType crmCourseType = htl.get(CrmCourseType.class, courseTypeId);
		return htl.getSessionFactory().getCurrentSession().createQuery("from CrmClass as c where c.crmCourseType=?",CrmClass.class).setParameter(0, crmCourseType).getResultList();
			
	}

}

	